<?php
class Model_Resource_Phone_Phone extends Zend_Db_Table
{
    protected $_name = 'phone_relation';
    protected $_primary = array(
        'phone_id',
        'related_phone_id',
    );

    public function fetchAllWithPhones($phoneId)
    {
        $phoneId = (int) $phoneId;
        $select = $this->select()->setIntegrityCheck(false);
        $select->from(array('m' => $this->_name), array())
            ->joinLeft(array('ph' => 'phone_entities'),
                'm.related_phone_id = ph.id'
            )
            ->where('m.phone_id = ?', (int) $phoneId)
        ;
        return $this->fetchAll($select);
    }
}

